﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;

namespace work_of_jump_100
{
    /// <summary>
    /// 角色小人类//1.贴图 2. keydown
    /// </summary>
    class Person
    {


        private const int step = 15;
        private const int personWidth = 100;
        private const int _gameWidth = 700;

        

        /// <summary>
        /// 绘制person
        /// </summary>
        /// <param name="g"></param>
        public Rectangle Rectangle { get; set; }


        public Person(Rectangle rec)
        {
            Rectangle = rec;

        }

        public void Draw(Graphics g)
        {
            g.DrawImage(Properties.Resources.personLeft, Rectangle);
        }


        /// <summary>
        /// 人物跳跃
        /// </summary>
        public void Jump()
        {
            this.Rectangle = new Rectangle(Rectangle.X,
                                           Rectangle.Y + Time.Y,
                                           Rectangle.Width,
                                           Rectangle.Height);
        }





        /// <summary>
        /// 处理键盘
        /// </summary>
        /// <param name="key"></param>
        public void KeyDown1(String key)
        {

            int newX = this.Rectangle.X;

            if (key == "A")
            {
                this.Rectangle = new Rectangle(Rectangle.X - step,
                                               Rectangle.Y,
                                               Rectangle.Width,
                                               Rectangle.Height);
                //防止左出界
                if (this.Rectangle.X < 0)
                    this.Rectangle = new Rectangle(0,
                                     Rectangle.Y,
                                     Rectangle.Width,
                                     Rectangle.Height);
            }

            if (key == "D")
            {
                this.Rectangle = new Rectangle(Rectangle.X + step,
                                               Rectangle.Y,
                                               Rectangle.Width,
                                               Rectangle.Height);
                //防止右出界
                if (this.Rectangle.X > (_gameWidth - personWidth))
                    this.Rectangle = new Rectangle(_gameWidth - personWidth,
                                     Rectangle.Y,
                                     Rectangle.Width,
                                     Rectangle.Height);
            }

            

        }

        public void KeyDown2(String key)
        {

            if (key == "W" & (Flag.flag==true))
            {

                Time.time = 0;
                this.Rectangle = new Rectangle(Rectangle.X,
                                                Rectangle.Y - 91,
                                                Rectangle.Width,
                                                Rectangle.Height);
            }
        }

    }

    public static class Flag
    {
        public static bool flag = false;
    }

}
